<template>
  <div class="home">
    <!-- 头部横幅 -->
    <div class="hero-banner">
      <div class="banner-content">
        <div class="banner-text">
          <h1 class="banner-title">校园二手交易</h1>
          <p class="banner-subtitle">让闲置游起来，让价值流动起来</p>
          <div class="banner-description">
            <span class="feature-tag">安全交易</span>
            <span class="feature-tag">快速发布</span>
            <span class="feature-tag">便捷沟通</span>
          </div>
          <div class="banner-actions">
            <el-button type="primary" size="large" @click="goToPublish" v-if="userStore.isLoggedIn" class="action-btn primary">
              <el-icon><Plus /></el-icon>
              立即发布
            </el-button>
            <el-button type="primary" size="large" @click="goToLogin" v-else class="action-btn primary">
              <el-icon><Key /></el-icon>
              立即登录
            </el-button>
            <el-button size="large" @click="goToProducts" class="action-btn secondary">
              <el-icon><Shop /></el-icon>
              逛逛看看
            </el-button>
          </div>
        </div>
        <div class="banner-image">
          <div class="floating-cards">
            <div class="card card-1">
              <div class="card-icon">📱</div>
              <div class="card-label">手机数码</div>
            </div>
            <div class="card card-2">
              <div class="card-icon">💻</div>
              <div class="card-label">电脑配件</div>
            </div>
            <div class="card card-3">
              <div class="card-icon">👟</div>
              <div class="card-label">运动鞋服</div>
            </div>
            <div class="card card-4">
              <div class="card-icon">📚</div>
              <div class="card-label">图书教材</div>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 装饰性元素 -->
      <div class="banner-decoration">
        <div class="decoration-circle circle-1"></div>
        <div class="decoration-circle circle-2"></div>
        <div class="decoration-circle circle-3"></div>
      </div>
    </div>



    <!-- 商品分类 -->
    <div class="category-section">
      <CategoryNav />
    </div>

    <!-- 热门商品 -->
    <div class="hot-products-section">
      <HotProducts />
    </div>

    <!-- 快速入口 -->
    <div class="quick-actions">
      <div class="section-header">
        <div class="header-content">
          <h3 class="section-title">快速入口</h3>
          <span class="section-subtitle">更多功能等你发现</span>
        </div>
        <div class="header-decoration">
          <div class="decoration-line"></div>
        </div>
      </div>
      
      <div class="actions-grid">
        <div class="action-item" @click="goToPublish" v-if="userStore.isLoggedIn">
          <div class="action-icon publish">
            <el-icon size="24"><Plus /></el-icon>
          </div>
          <div class="action-text">
            <div class="action-title">发布商品</div>
            <div class="action-desc">出售闲置物品</div>
          </div>
          <div class="action-arrow">
            <el-icon><ArrowRight /></el-icon>
          </div>
        </div>
        
        <div class="action-item" @click="goToUserCenter" v-if="userStore.isLoggedIn">
          <div class="action-icon profile">
            <el-icon size="24"><User /></el-icon>
          </div>
          <div class="action-text">
            <div class="action-title">个人中心</div>
            <div class="action-desc">管理我的信息</div>
          </div>
          <div class="action-arrow">
            <el-icon><ArrowRight /></el-icon>
          </div>
        </div>
        
        <div class="action-item" @click="goToAdmin" v-if="userStore.isAdmin">
          <div class="action-icon admin">
            <el-icon size="24"><Setting /></el-icon>
          </div>
          <div class="action-text">
            <div class="action-title">后台管理</div>
            <div class="action-desc">系统管理功能</div>
          </div>
          <div class="action-arrow">
            <el-icon><ArrowRight /></el-icon>
          </div>
        </div>
        
        <div class="action-item" @click="goToLogin" v-if="!userStore.isLoggedIn">
          <div class="action-icon login">
            <el-icon size="24"><Key /></el-icon>
          </div>
          <div class="action-text">
            <div class="action-title">登录账户</div>
            <div class="action-desc">享受更多功能</div>
          </div>
          <div class="action-arrow">
            <el-icon><ArrowRight /></el-icon>
          </div>
        </div>
        
        <div class="action-item" @click="goToRegister" v-if="!userStore.isLoggedIn">
          <div class="action-icon register">
            <el-icon size="24"><UserFilled /></el-icon>
          </div>
          <div class="action-text">
            <div class="action-title">注册账户</div>
            <div class="action-desc">开启交易之旅</div>
          </div>
          <div class="action-arrow">
            <el-icon><ArrowRight /></el-icon>
          </div>
        </div>
      </div>
    </div>

    <!-- 用户状态展示 -->
    <div class="latest-users-section" v-if="userStore.isAdmin">
      <LatestUsers />
    </div>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'
import { Plus, User, Setting, Key, UserFilled, Shop, ArrowRight } from '@element-plus/icons-vue'
import SearchBar from '@/components/SearchBar.vue'
import CategoryNav from '@/components/CategoryNav.vue'
import HotProducts from '@/components/HotProducts.vue'
import LatestUsers from '@/components/LatestUsers.vue' 

const router = useRouter()
const userStore = useUserStore()

// 导航方法
const goToProducts = () => {
  router.push('/products')
}

const goToPublish = () => {
  router.push('/publish')
}

const goToLogin = () => {
  router.push('/login')
}

const goToRegister = () => {
  router.push('/register')
}

const goToUserCenter = () => {
  router.push('/user/profile')
}

const goToAdmin = () => {
  router.push('/admin')
}
</script>

<style scoped>
.home {
  min-height: 100vh;
  background: linear-gradient(180deg, #f8f9fa 0%, #ffffff 100%);
  position: relative;
  overflow-x: hidden;
}

.home::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
    radial-gradient(circle at 20% 80%, rgba(255, 107, 53, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(79, 172, 254, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 40% 40%, rgba(240, 147, 251, 0.02) 0%, transparent 50%);
  pointer-events: none;
  z-index: -1;
}

/* 头部横幅 */
.hero-banner {
  background: linear-gradient(135deg, #ff6b35 0%, #f7931e 50%, #ff8c42 100%);
  color: white;
  padding: 80px 0;
  position: relative;
  overflow: hidden;
  margin-bottom: 60px;
}

.banner-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 2;
}

.banner-text {
  flex: 1;
  max-width: 550px;
}

.banner-title {
  font-size: 56px;
  font-weight: 800;
  margin-bottom: 20px;
  line-height: 1.1;
  background: linear-gradient(45deg, #ffffff, #f0f8ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: fadeInUp 1s ease-out;
}

.banner-subtitle {
  font-size: 22px;
  margin-bottom: 25px;
  opacity: 0.95;
  line-height: 1.4;
  font-weight: 400;
  animation: fadeInUp 1s ease-out 0.2s both;
}

.banner-description {
  display: flex;
  gap: 12px;
  margin-bottom: 35px;
  flex-wrap: wrap;
  animation: fadeInUp 1s ease-out 0.4s both;
}

.feature-tag {
  background: rgba(255, 255, 255, 0.2);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  transition: all 0.3s ease;
}

.feature-tag:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

.banner-actions {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  animation: fadeInUp 1s ease-out 0.6s both;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 16px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
  cursor: pointer;
}

.action-btn.primary {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.action-btn.primary:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
}

.action-btn.secondary {
  background: transparent;
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.5);
}

.action-btn.secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
}

.banner-image {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.floating-cards {
  position: relative;
  width: 400px;
  height: 300px;
}

.card {
  position: absolute;
  width: 100px;
  height: 100px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(15px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  animation: float 4s ease-in-out infinite;
  transition: all 0.3s ease;
  cursor: pointer;
}

.card:hover {
  transform: scale(1.1) translateY(-10px);
  background: rgba(255, 255, 255, 0.25);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.card-icon {
  font-size: 32px;
  margin-bottom: 4px;
}

.card-label {
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  line-height: 1.2;
}

.card-1 {
  top: 20px;
  left: 50px;
  animation-delay: 0s;
}

.card-2 {
  top: 100px;
  right: 40px;
  animation-delay: 1s;
}

.card-3 {
  bottom: 40px;
  left: 80px;
  animation-delay: 2s;
}

.card-4 {
  top: 60px;
  right: 120px;
  animation-delay: 3s;
}

@keyframes float {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(2deg); }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 装饰性元素 */
.banner-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.decoration-circle {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  animation: float 6s ease-in-out infinite;
}

.circle-1 {
  width: 100px;
  height: 100px;
  top: 10%;
  right: 10%;
  animation-delay: 0s;
}

.circle-2 {
  width: 60px;
  height: 60px;
  bottom: 20%;
  left: 15%;
  animation-delay: 2s;
}

.circle-3 {
  width: 80px;
  height: 80px;
  top: 60%;
  right: 20%;
  animation-delay: 4s;
}

/* 主要内容区域 */
.home > div:not(.hero-banner) {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* 内容区域间距优化 */
.search-section {
  margin-bottom: 50px;
}

.category-section {
  margin-bottom: 60px;
}

.hot-products-section {
  margin-bottom: 60px;
}

.latest-users-section {
  margin-bottom: 60px;
}

/* 快速入口 */
.quick-actions {
  background: #fff;
  padding: 50px;
  border-radius: 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(255, 107, 53, 0.1);
  position: relative;
  overflow: hidden;
  margin-bottom: 60px;
}

.quick-actions::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #ff6b35 0%, #f7931e 100%);
}

.section-header {
  display: flex;
  align-items: center;
  margin-bottom: 40px;
  position: relative;
}

.header-content {
  flex: 1;
}

.section-title {
  margin: 0 0 8px 0;
  font-size: 32px;
  color: #2c3e50;
  font-weight: 700;
  letter-spacing: -0.5px;
  position: relative;
}

.section-title::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 0;
  width: 40px;
  height: 4px;
  background: linear-gradient(90deg, #ff6b35, #f7931e);
  border-radius: 2px;
}

.section-subtitle {
  color: #7f8c8d;
  font-size: 16px;
  font-weight: 400;
  letter-spacing: -0.1px;
}

.header-decoration {
  flex-shrink: 0;
}

.decoration-line {
  width: 60px;
  height: 2px;
  background: linear-gradient(90deg, transparent, #ff6b35);
  border-radius: 1px;
}

.actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
  max-width: 900px;
  margin: 0 auto;
}

.action-item {
  display: flex;
  align-items: center;
  padding: 28px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  background: linear-gradient(145deg, #ffffff 0%, #f8f9fa 100%);
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
}

.action-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 107, 53, 0.1), transparent);
  transition: left 0.6s;
}

.action-item:hover::before {
  left: 100%;
}

.action-item:hover {
  transform: translateY(-8px) scale(1.02);
  box-shadow: 0 20px 40px rgba(255, 107, 53, 0.15);
  border-color: #ff6b35;
  background: linear-gradient(145deg, #ffffff 0%, #fff5f2 100%);
}

.action-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 20px;
  color: white;
  flex-shrink: 0;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
  position: relative;
}

.action-item:hover .action-icon {
  transform: scale(1.15);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.action-icon.publish {
  background: linear-gradient(135deg, #ff6b35 0%, #f7931e 50%, #ff8c42 100%);
  box-shadow: 0 6px 20px rgba(255, 107, 53, 0.3);
}

.action-icon.profile {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 50%, #0dd3ff 100%);
  box-shadow: 0 6px 20px rgba(79, 172, 254, 0.3);
}

.action-icon.admin {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #8b5fbf 100%);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.3);
}

.action-icon.login {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 50%, #2ed5a6 100%);
  box-shadow: 0 6px 20px rgba(67, 233, 123, 0.3);
}

.action-icon.register {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 50%, #ff6b8a 100%);
  box-shadow: 0 6px 20px rgba(240, 147, 251, 0.3);
}

.action-text {
  flex: 1;
}

.action-title {
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 6px;
  letter-spacing: -0.2px;
}

.action-desc {
  font-size: 14px;
  color: #7f8c8d;
  line-height: 1.4;
  letter-spacing: -0.1px;
}

.action-arrow {
  color: #cbd5e0;
  transition: all 0.3s ease;
  opacity: 0;
  transform: translateX(-10px);
}

.action-item:hover .action-arrow {
  opacity: 1;
  transform: translateX(0);
  color: #ff6b35;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .hero-banner {
    padding: 60px 0;
    margin-bottom: 40px;
  }
  
  .banner-content {
    flex-direction: column;
    text-align: center;
    gap: 40px;
  }
  
  .banner-title {
    font-size: 40px;
    margin-bottom: 15px;
  }
  
  .banner-subtitle {
    font-size: 18px;
    margin-bottom: 20px;
  }
  
  .floating-cards {
    width: 280px;
    height: 200px;
  }
  
  .card {
    width: 70px;
    height: 70px;
  }
  
  .card-icon {
    font-size: 24px;
  }
  
  .card-label {
    font-size: 10px;
  }
  
  .actions-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  .action-item {
    padding: 24px;
    border-radius: 16px;
  }
  
  .action-icon {
    width: 56px;
    height: 56px;
    margin-right: 16px;
  }
  
  .action-title {
    font-size: 16px;
  }
  
  .quick-actions {
    padding: 40px 30px;
    border-radius: 20px;
    margin-bottom: 40px;
  }
  
  .section-title {
    font-size: 26px;
  }
  
  .home > div:not(.hero-banner) {
    padding: 0 15px;
  }
  
  .search-section,
  .category-section,
  .hot-products-section,
  .latest-users-section {
    margin-bottom: 40px;
  }
}

@media (max-width: 480px) {
  .hero-banner {
    padding: 40px 0;
  }
  
  .banner-title {
    font-size: 32px;
    line-height: 1.2;
  }
  
  .banner-subtitle {
    font-size: 16px;
    margin-bottom: 15px;
  }
  
  .banner-description {
    gap: 8px;
    margin-bottom: 25px;
  }
  
  .feature-tag {
    padding: 4px 12px;
    font-size: 12px;
  }
  
  .banner-actions {
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    align-items: center;
  }
  
  .action-btn {
    width: 220px;
    justify-content: center;
  }
  
  .floating-cards {
    width: 240px;
    height: 160px;
  }
  
  .card {
    width: 60px;
    height: 60px;
  }
  
  .card-icon {
    font-size: 20px;
  }
  
  .card-label {
    font-size: 9px;
  }
  
  .home > div:not(.hero-banner) {
    padding: 0 10px;
  }
  
  .quick-actions {
    padding: 30px 20px;
    margin-bottom: 30px;
  }
  
  .section-title {
    font-size: 22px;
  }
  
  .action-item {
    padding: 20px;
    flex-direction: column;
    text-align: center;
  }
  
  .action-icon {
    margin-right: 0;
    margin-bottom: 12px;
  }
  
  .action-arrow {
    display: none;
  }
  
  .search-section,
  .category-section,
  .hot-products-section,
  .latest-users-section {
    margin-bottom: 30px;
  }
}
</style> 